
import getData from '../getData/api.js'
import {Message} from "element-ui";

const state = {
    testData: [],
    userName:'admin',//用户名
    isCollapse:'',
}

const getters = {
    testGetter(state) {
        return state.testData;
    },
    isCollapseGetter(state){
        return state.isCollapse;
    }
}

const mutations = {
    testMutation(state, data) {
        state.testData = data
    },
    //修改用户名
    SET_USER_NAME(state, data) {
        state.testData = data
    },
    SET_ISCOLLAPSE_STATUS(state,data){
        state.isCollapse = data
    }
}

const actions = {
    testAction({state, commit}, params) {
        return getData.getHomeData(params)
            .then((res) => {
                return commit('testMutation', res);
            })
            .catch((err)=>{
                // console.log(err)
            })
    },
    changePassword({state, commit}, params) {
        return getData.changePasswordData(params)
            .then((res) => {
                if (res.code == 200){
                    Message.success(res.message);
                }else if(res.code != 200){
                    Message.error(res.message);
                }
            })
            .catch((err)=>{
                // console.log(err)
            })
    },
    reviseUserName({state, commit}, params) {
        return commit('SET_USER_NAME', params);
    },
}

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}